/*
 * Copyright (c) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.api.client.auth.oauth;


/**
 * Generic OAuth 1.0a URL to request to exchange the temporary credentials token (or "request
 * token") for a long-lived credentials token (or "access token") from an authorization server.
 * <p>
 * Use {@link #execute()} to execute the request. The long-lived access token acquired with this
 * request is found in {@link com.google.api.client.auth.oauth.OAuthCredentialsResponse#token} . This token must be stored. It may
 * then be used to authorize HTTP requests to protected resources by using {@link com.google.api.client.auth.oauth.OAuthParameters}.
 * @author Mischa Dasberg
 * @since 1.15
 */
public final class OAuthAccessToken extends AbstractOAuthToken {

    /**
     * Required temporary token. It is retrieved from the {@link com.google.api.client.auth.oauth.OAuthCredentialsResponse#token}
     * returned from {@link com.google.api.client.auth.oauth.OAuthGetTemporaryToken#execute()}.
     */
    private String temporaryToken;

    /**
     * Required verifier code received from the server when the temporary token was authorized. It is
     * retrieved from {@link com.google.api.client.auth.oauth.OAuthCallbackUrl#verifier}.
     */
    private String verifier;

    /**
     * Constructor.
     * @param authorizationServerUrl encoded authorization server URL
     * @param httpMethod             The http method.
     */
    public OAuthAccessToken(final String authorizationServerUrl, final String httpMethod) {
        super(authorizationServerUrl, httpMethod);
    }

    @Override
    public OAuthParameters createParameters() {
        final OAuthParameters result = super.createParameters();
        result.token = temporaryToken;
        result.verifier = verifier;
        return result;
    }

    /**
     * Get the temporary token.
     * @return temporaryToken The temporary token.
     */
    public String getTemporaryToken() {
        return temporaryToken;
    }

    /**
     * Set the temporary token.
     * @peturn temporaryToken The temporary token.
     */
    public void setTemporaryToken(final String temporaryToken) {
        this.temporaryToken = temporaryToken;
    }

    /**
     * Get the verifier.
     * @return verifier The verifier.
     */
    public String getVerifier() {
        return verifier;
    }

    /**
     * Set the verifier.
     * @param verifier The verifier.
     */
    public void setVerifier(String verifier) {
        this.verifier = verifier;
    }
}
